#include<bits/stdc++.h>
using namespace std;
#pragma warning(disable:4996)
int n, m;
vector<int> v[102];
int head[102];
int anshead, ansnum = 0;
vector<int> temp;
vector<int> ans;
bool visited[102];

void dfs(int cur) {
	if (visited[cur]) return;

	visited[cur] = true;
	temp.push_back(cur);


	for (auto each : v[cur]) {
		if (!visited[each]) {
			dfs(each);
		}
	}
	if (temp.size() > ans.size()) {
		ans = temp;
	}

	temp.pop_back();


}

int main() {
	scanf("%d %d", &n, &m);


	fill(head, head + 102, 0);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
		head[a]++;
		head[b]++;
	}
	for (int i = 1; i <= n; i++) {
		sort(v[i].begin(), v[i].end());
	}
	bool flag = false;
	for (int i = 1; i <= n; i++) {
		flag = true;
		temp.clear();
		fill(visited, visited + 102, false);
		dfs(i);
		if (ans.size() > ansnum) {
			anshead = i;
			ansnum = ans.size();
		}
	}
	printf("%d %d", anshead, ansnum);

	system("pause");
	return 0;
}